package jellyfishumbrella.tikis;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;

import com.jellyfishumbrella.GL.AbstractGameLogic;
import com.jellyfishumbrella.GL.Animator;

public class GameLogic extends AbstractGameLogic {
	public static double	SCALING	= 1;
	public static Volcano	volcanoIsland;

	public GameLogic() {
		super(new KeyboardMouse(renderGL));
	}

	public void init() {
		// this runs AFTER we're connected to Renderer

		
		preLoadTextures();
		
		Surfaces.setup();

		animator = new Animator(this);
		animator.add(renderGL.camera);

		volcanoIsland = new Volcano(this);
	}

	/**
	 * Notification that a frame is being rendered. Responsible for running game
	 * logic and rendering the scene.
	 */
	public void gameLogic() {
		Display.sync(refreshRate);

		// work out how long its been since the last update, this
		// will be used to calculate how far the entities should
		// move this loop
		long delta = getTime() - lastLoopTime;
		lastLoopTime = getTime();
		lastFpsTime += delta;
		fps++;

		// update our FPS counter if a second has passed
		if (lastFpsTime >= 1000) {
			System.out.println("fps: " + fps + "   currTime: " + getTime());
			lastFpsTime = 0;
			fps = 0;
		}

		// if escape has been pressed, stop the game
		if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
			gameRunning = false;
			shutdown();
		}

		update(lastLoopTime);

		// updateLOD();
	}

	public void preLoadTextures() {
		renderGL.textureHash.loadTexture("testUV_grad");
		renderGL.textureHash.loadTexture("testFractal_Noise");
		renderGL.textureHash.loadTexture("test_ALT_GRAD");
	}

}
